
# wget https://swift.org/builds/swift-5.3-release/ubuntu2004/swift-5.3-RELEASE/swift-5.3-RELEASE-ubuntu20.04.tar.gz

# https://github.com/kabiroberai/linux-app/
# https://github.com/elihwyma/ExampleXcodeApp/blob/master/README.md

if [ ! -e /usr/local/swift ]; then
 #   wget https://download.swift.org/swift-5.10-release/ubuntu2204/swift-5.10-RELEASE/swift-5.10-RELEASE-ubuntu22.04.tar.gz
    wget https://download.swift.org/swift-5.9-release/ubuntu2204/swift-5.9-RELEASE/swift-5.9-RELEASE-ubuntu22.04.tar.gz
    tar xf swift-5.10-RELEASE-ubuntu22.04.tar.gz
    mv swift-5.10-RELEASE-ubuntu22.04 /usr/local/swift
fi


git clone https://github.com/kabiroberai/swift-package-manager -b kabir/develop
cd swift-package-manager 
swift build
cd .build/debug/
cd /usr/local/swift/usr/bin/
rm swift-package swift-build swift-run swift-experimental-sdk 
cd -
cp swift-package swift-build swift-run swift-experimental-sdk /usr/local/swift/usr/bin/


cd /root/src

# unxip
which unxip || {
    apt install libxml2-dev autoconf -y
    git clone https://github.com/DimitriFourny/unxip.git
    cd unxip ; make; cp unxip /usr/local/bin/
    cd -

    git clone https://github.com/mackyle/xar
    cd xar/xar
    sed -i 's/OpenSSL_add_all_ciphers/OPENSSL_init_crypto/g' configure.ac
    ./autogen.sh && make && cp src/xar /usr/local/bin
    cd -

    git clone https://github.com/matteyeux/iOS-Utilities.git
    cd iOS-Utilities
    make && cp pbzx /usr/local/bin
    cd -
}


[ -e Xcode_15.3.xip ] || wget https://download.developer.apple.com/Developer_Tools/Xcode_15.3/Xcode_15.3.xip

xar -xf Xcode_15.xip && pbzx Content | cpio -i
ls Xcode.app

git clone https://github.com/kabiroberai/swift-sdk-darwin.git -b develop
cd swift-sdk-darwin
bash build.sh ubuntu22.04 /root/src/Xcode.app/Contents/Developer
# sh output/darwin.artifactbundle/install.sh
rm -rf /root/.swiftpm/swift-sdks/darwin.artifactbundle
swift experimental-sdk install output/darwin.artifactbundle

# edit file
# /root/.swiftpm/swift-sdks/darwin.artifactbundle/swift-sdk.json